package login.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import login.service.Impl.LoServiceImpl;

import util.DB;

public class LoController extends HttpServlet {

	
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doPost(request, response);
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			String action=request.getParameter("action");
			if ("login".equalsIgnoreCase(action)) {
				String uname=request.getParameter("uname");
				String pswd=request.getParameter("pswd");
				int n=loServiceImpl.login(db, uname, pswd);
				if (n>0) {
					request.getRequestDispatcher("index.jsp").forward(request, response);
				} else {
					request.getRequestDispatcher("login.jsp").forward(request, response);
				}
			}
			
		
	}

	
	public void init() throws ServletException {
		loServiceImpl=new LoServiceImpl();
		db=new DB();
	}
private LoServiceImpl loServiceImpl=null;
private DB db=null;

}
